#.rst:
# Config file for the raicommon CMake package
# ----------
# This config sets the following variables:
# ``raicommon_FOUND``
#  True, if the system has raicommon.
# ``raicommon_INCLUDE_DIRS``
#  Path to the raicommon header files.
# ``raicommon_LIBRARIES``
#  Paths to the raicommon core libraries.
#
#=============================================================================
# Copyright (C) 2018 Jemin Hwangbo
# All rights reserved.
# https://bitbucket.org/leggedrobotics/rai_common
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

# We include this module to streamline generation of standard CMake variables
# (https://cmake.org/cmake/help/v3.5/module/FindPackageHandleStandardArgs.html)
include(FindPackageHandleStandardArgs)
unset(raicommon_FOUND)

# Setup the raicommon package variables
set(raicommon_INCLUDE_DIRS "@CONFIG_INCLUDE_DIRS@")
set(raicommon_LIBRARIES_DIR "@CONFIG_LIBRARIES_DIRS@")
set(raicommon_LIBRARIES "@CONFIG_LIBRARIES@")
set(raicommon_EXPORTED_TARGETS "@CONFIG_EXPORTED_TARGETS@")

# Check if libraries target should be
if(USE_EXPORTED_LIBS)
  # Construct list with full paths of libraries to link against
  foreach(library ${raicommon_EXPORTED_TARGETS})
    find_library(${library}_LIB
      NAMES ${library}
      PATHS ${raicommon_LIBRARIES_DIR}
      NO_DEFAULT_PATH
      )
    list(APPEND raicommon_LIBRARIES ${${library}_LIB})
  endforeach()
else()
  list(APPEND raicommon_LIBRARIES ${raicommon_EXPORTED_TARGETS})
endif()

# Check if the path variables where set succesfully
find_package_handle_standard_args(raicommon
  REQUIRED_VARS
    raicommon_INCLUDE_DIRS
    raicommon_LIBRARIES)

# Check if package search and setup was successful overall
if(raicommon_FOUND)
  message(STATUS "raicommon: config: ${CMAKE_CURRENT_LIST_FILE}")
  message(STATUS "raicommon: includes: ${raicommon_INCLUDE_DIRS}")
  message(STATUS "raicommon: libraries: ${raicommon_LIBRARIES}")
endif()

# EOF
